using AutojsController.ViewModels;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.VisualTree;
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;

namespace AutojsController.Views;

public partial class MobileItemView : UserControl
{
    public MobileItemView()
    {
        InitializeComponent();
    }

    private void MobileItem_PointerPressed(object sender, PointerPressedEventArgs e)
    {
        if (e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
        {
            if (DataContext is MobileItemViewModel mobitem)
            {
                if (this.FindAncestorOfType<MobileView>()?.DataContext is MobileViewModel mobvm)
                {
                    mobvm.SelectMobileOrNot(mobitem);
                }
                else if (this.FindAncestorOfType<GroupView>()?.DataContext is GroupViewModel grpvm)
                {
                    grpvm.SelectMobileOrNot(mobitem);
                }
            }
        }
    }
}